﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Presenter;
using DataTransferObject;

namespace View
{
    public partial class ViewForm : Form, IViewForm
    {
        private StudentPresenter presenter;

        public ViewForm()
        {
            InitializeComponent();
            presenter = new StudentPresenter(this);
        }

        #region Property


        public String CurrentName
        {
            get
            {
                return txtName.Text;
            }
            set
            {
                txtName.Text = value;
            }
        }

        public String CurrentStudentCode
        {
            get
            {
                return txtStudentCode.Text;
            }
            set
            {
                txtStudentCode.Text = value;
            }
        }

        public String CurrentClass
        {
            get
            {
                return txtClass.Text;
            }
            set
            {
                txtClass.Text = value;
            }
        }

        public String CurrentSex
        {
            get
            {
                return txtSex.Text;
            }
            set
            {
                txtSex.Text = value;
            }
        }

        #endregion

        public void ShowStudentList(IList<Student> list)
        {
            studentBindingSource.DataSource = list;            
        }

        public void AddNewStudent(Student student)
        {
            studentBindingSource.Add(student);
        }

        private void ViewForm_Load(object sender, EventArgs e)
        {
            presenter.InitData();
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            presenter.AddNewStudentToData();
        }

        private void clearButton_Click(object sender, EventArgs e)
        {
            CurrentName = "";
            CurrentStudentCode = "";
            CurrentClass = "";
        }
    }
}
